package com.example.rabbit;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Login
 * Package: com.example.rabbit
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-06-08
 * Time: 19:43
 */

public class Login {
    //发消息发给一个队列
    public static final String QUEUE_USER = "user";


    //发消息
    public static void main(String[] args) throws IOException, TimeoutException {
        //创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置IP
        factory.setHost("192.168.86.131");
        //设置用户名
        factory.setUsername("admin");
        //设置密码
        factory.setPassword("123");
        //以上成功连接到队列

        //产生信道
        Connection connection = factory.newConnection();
        //获取信道
        Channel channel = connection.createChannel();
        //申明队列
        channel.queueDeclare(QUEUE_USER,true,true,false,null);
        //发送消息实体
        User user = new User("user","123","138888888888","123@qq.com");

        channel.basicPublish("",QUEUE_USER,null,user.toString().getBytes());

        System.out.println("消息发送成功!");



    }




}
